import { AppModel } from 'app/models/kdsConfig';
import { PlayAudioService } from './../../components/play-audio';
import { ConfigSvr } from './../../services/config';
import { Component, OnInit } from '@angular/core';

@Component({
    selector: 'sound-setup',
    styleUrls: ['./index.scss'],
    template: `
        <div class="soundsetup-container">
            <ul>
                <li *ngFor="let option of options" style="display: flex;" [hidden]="!isValidOrderSetupOptionNames(option.name)">
                     <options [option]="option"></options>
                </li>
            </ul>
        </div>
    `
})
export class SoundSetup implements OnInit {
    constructor(private configSvr: ConfigSvr) { }
    isValidOrderSetupOptionNames(name) {
        return this.validOrderSetupOptionNames.indexOf(name) > -1;
    }

    get validOrderSetupOptionNames(): Array<string> {
        const appModel = this.configSvr.appConfig.model;
        let options;
        switch (appModel) {
            case AppModel.FastFood:
                options = ["soundConfigIsOpenNewOrderSound"]
            case AppModel.HotPot:
                options = ["soundConfigIsOpenNewOrderSound"] //"orderConfigCombined",
                break;
            default:
                break;
        }
        return options;
    }

    ngOnInit() { }
    commonOperation(option) {
        option.checked = !option.checked;
        this.configSvr.soundConfig = {
            isOpenNewOrderSound: this.options[0].checked,//新单的声音
            isOpenRemindSound: this.options[1].checked,//催菜提示音
            isOpenRefundSound: false//this.options[2].checked//退菜提示音
        }
    }
    options = [
        {
            name: "soundConfigIsOpenNewOrderSound",
            "title": "新单提示音",
            type: "switch",
            checked: this.configSvr.soundConfig.isOpenNewOrderSound,
            operation: (option) => {
                this.commonOperation(option);
                PlayAudioService.current.newOrder();
            }
        }, {
            name: "soundConfigIsOpenRemindSound",
            "title": "退菜提示音",
            type: "switch",
            checked: this.configSvr.soundConfig.isOpenRefundSound,
            operation: (option) => {
                this.commonOperation(option);
                PlayAudioService.current.refundOrder();
            }
        },
        {
            name: "soundConfigIsOpenRefundSound",
            "title": "催菜提示音",
            type: "switch",
            checked: this.configSvr.soundConfig.isOpenRemindSound,
            operation: (option) => {
                this.commonOperation(option);
                PlayAudioService.current.remindOrder();
            }
        }
    ]
}

